
<template>

  <div>
    <el-form ref="formRef" :model="form" label-width="80px">

      <el-form-item label="手机" prop="username">
        <el-input v-model="form.mobile" />
      </el-form-item>

      <el-form-item label="入职时间" required>
        <el-form-item prop="date1">
          <el-date-picker v-model="form.correctionTime" type="date" placeholder="选择日期" style="width: 100%;" />
        </el-form-item>
      </el-form-item>
      <el-form-item label="员工头像">
        <!-- <img :src="form.staffPhoto" alt="图片没有显示的文字" width="100"> -->
        <Uploadlmg :key="form.id" :src="form.staffPhoto" @tupian="tupianwei" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存更新</el-button>
        <el-button>返回</el-button>
      </el-form-item>
    </el-form></div>
</template>
<script>
// 与前面的的获取更新的接口一模一样拿过来即可
import { AdddataDaoru, updateUserInfoRequest } from '@/api/emPloyees'

export default {
  name: '',
  data() {
    return {
      form: {
        mobile: '',
        correctionTime: '',
        staffPhoto: ''
      },
      rules: {
        // mobile: [
        //   { required: true, message: '请输入手机号', trigger: 'blur' },
        //   { validator: validatePass, trigger: 'change' }
        // ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  }, created() {
    this.AdddataDaoruname()
  },

  methods: {
    // 获取员工基本信息(姓名与密码)
    async AdddataDaoruname() {
      try {
        const res = await AdddataDaoru(this.$route.query?.id || '')
        console.log(1111111111111111111111111, res)
        if (res.success) {
          // this.form.username = res.data.username
          // this.form.password = res.data.password
          this.form = res.data
        }
      } catch (err) {
        console.log('AdddataDaoru: ', err)
      }
    },
    // 保存员工基本信息请求
    async updateUserInfo() {
      try {
        const res = await updateUserInfoRequest(this.form)
        console.log(222222, res)
        if (res.success) {
          this.$message('更新成功')
          // back()就是会把你推倒上一级路由
          this.$router.back()
        } else {
          this.$message.error(res.message)
        }
      } catch (err) {
        console.log('保存出错')
      }
    },
    onSubmit() {
      this.updateUserInfo()
      // this.$emit('gengxing')
    },
    tupianwei(res) {
      this.form.staffPhoto = res
      console.log('上传成功', res)
    }
  }}
</script>
